package com.classify.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 解决跨域问题
 * */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    //跨域问题
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        //addMapping 那些目录允许跨域访问
        //allowedOrigins 允许那些网站
        //allowedMethods 允许那些方法
        //allowCredentials访问时是否需要验证
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
                .allowCredentials(true)
                .maxAge(3600)
                .allowedHeaders("*");
    }
}
